<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ClinchHouse extends Model
{
    use HasFactory;

    protected $table = 'clinch_house';

    public function house()
    {
        return $this->belongsTo(House::class,'house_id');
    }

    public static function getBrokerData($type,$intermediary_id,$where)
    {
        $house_id = self::where(['intermediary_id'=>$intermediary_id,'type'=>$type])->pluck('house_id');
        if (!empty($where)){
            return House::with('houseAttr')
                ->whereIn('id',$house_id)
                ->where('house_address','like',"%$where%")
                ->orWhere('house_area','like',"%$where%")
                ->find($house_id);
        }
        return House::with('houseAttr')
            ->whereIn('id',$house_id)
            ->get();
    }
}
